package bview

import (
	"github.com/gin-gonic/gin"
)

//login
const LOGIN_SESSION_TIME_S = 7200
const OK_LOGIN_SUCCESS string = "login success"
const COOKIE_DOMAIN string = "localhost"

//public
const ERROR_OTHER_INTERNAL_ERROR string = "internal error: other reasons"
const ERROR_POST_PARA_ERROR string = "post para error"
const ERROR_GET_PARA_ERROR string = "get para error"
const ERROR_LOGIN_STATE_TIMEOUT string = "login state timeout, please login again"
const DEFAULT_NUMBER_OF_PAGES = 5
const POSTOK = true
const POSTERR = false

//block
const DEFAULT_BLOCK_LIST_PAGE_STRING string = "1"
const DEFAULT_NUMBER_OF_BLOCK_IN_ONE_PAGE string = "10"
const DEFAULT_BLOCK_ID string = "XXX" //default will crash!
const OK_BLOCK_ADD_SUCCESS string = "block add success"
const OK_BLOCK_EDIT_SUCCESS string = "block edit success"

//article
const DEFAULT_ARTICLE_LIST_BLOCKID_STRING string = "0" //dump, 事实上没有这个板块, 但是因为是数字所以不会500
const DEFAULT_ARTICLE_LIST_PAGE_STRING string = "1"
const DEFAULT_NUMBER_OF_ARTICLE_IN_ONE_PAGE string = "15"
const DEFAULT_ARTICLE_ID string = "XXX" //default will crash!
const OK_ARTICLE_ADD_SUCCESS string = "article add success"
const OK_ARTICLE_EDIT_SUCCESS string = "article edit success"

type cmsuserData struct {
	Username string `json:"username" binding:"required"`
	Password string `json:"password" binding:"required"`
}

type blockaddData struct {
	Parentid string `json:"blockParentid" binding:"required"`
	Title    string `json:"blockTitle" binding:"required"`
	Describe string `json:"blockDescribe" binding:"required"`
	State    string `json:"blockState" binding:"required"`
}

type blockeditData struct {
	Id       string `json:"blockId" binding:"required"`
	Parentid string `json:"blockParentid" binding:"required"`
	Title    string `json:"blockTitle" binding:"required"`
	Describe string `json:"blockDescribe" binding:"required"`
	State    string `json:"blockState" binding:"required"`
}

type articleaddData struct {
	Articleblockid  string `json:"articleBlockid" binding:"required"`
	Articlepriority string `json:"articlePriority" binding:"required"`
	Articletitle    string `json:"articleTitle" binding:"required"`
	Articlekeywords string `json:"articleKeywords" binding:"required"`
	Articlebrief    string `json:"articleBrief" binding:"required"`
	Articlecontent  string `json:"articleContent" binding:"required"`
	//Articletype     string `json:"articleType" binding:"required"`
	Articleremark string `json:"articleRemark" binding:"required"`
	Articlestate  string `json:"articleState" binding:"required"`
}

type articleeditData struct {
	Articleid       string `json:"articleId" binding:"required"`
	Articleblockid  string `json:"articleBlockid" binding:"required"`
	Articlepriority string `json:"articlePriority" binding:"required"`
	Articletitle    string `json:"articleTitle" binding:"required"`
	Articlekeywords string `json:"articleKeywords" binding:"required"`
	Articlebrief    string `json:"articleBrief" binding:"required"`
	Articlecontent  string `json:"articleContent" binding:"required"`
	//Articletype     string `json:"articleType" binding:"required"`
	Articleremark string `json:"articleRemark" binding:"required"`
	Articlestate  string `json:"articleState" binding:"required"`
}

const POST_200_OK_PRESTRING string = "0#"
const POST_200_ERROR_PRESTRING string = "1#"

/*
 * parse send POST, use only in the end of (view model) of POST
 * para: c *gin.Context, s string, state bool
 * return None
 *
 * note: with c.String inside
 */
func parseSendPOST(c *gin.Context, s string, state bool) {
	if state {
		c.String(200, POST_200_OK_PRESTRING+s)
	} else {
		c.String(200, POST_200_ERROR_PRESTRING+s)
	}
}
